package com.android.epidemic_assistant.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.example.epidemic_assistant.util.StringConverter;
import java.util.List;

import com.example.epidemic_assistant.bean.UserBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "USER_BEAN".
*/
public class UserBeanDao extends AbstractDao<UserBean, Long> {

    public static final String TABLENAME = "USER_BEAN";

    /**
     * Properties of entity UserBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property IsAdmin = new Property(1, boolean.class, "isAdmin", false, "IS_ADMIN");
        public final static Property UserName = new Property(2, String.class, "userName", false, "USER_NAME");
        public final static Property UserPass = new Property(3, String.class, "userPass", false, "USER_PASS");
        public final static Property Name = new Property(4, String.class, "name", false, "NAME");
        public final static Property UserPhoto = new Property(5, String.class, "userPhoto", false, "USER_PHOTO");
        public final static Property Age = new Property(6, String.class, "age", false, "AGE");
        public final static Property Sex = new Property(7, String.class, "sex", false, "SEX");
        public final static Property IdCard = new Property(8, String.class, "idCard", false, "ID_CARD");
        public final static Property FamilyAddress = new Property(9, String.class, "familyAddress", false, "FAMILY_ADDRESS");
        public final static Property HealthImgPath = new Property(10, String.class, "healthImgPath", false, "HEALTH_IMG_PATH");
        public final static Property HealthMaImgPath = new Property(11, String.class, "healthMaImgPath", false, "HEALTH_MA_IMG_PATH");
        public final static Property IsMaintain = new Property(12, boolean.class, "isMaintain", false, "IS_MAINTAIN");
        public final static Property Places = new Property(13, String.class, "places", false, "PLACES");
        public final static Property People = new Property(14, String.class, "people", false, "PEOPLE");
        public final static Property Temperature = new Property(15, String.class, "temperature", false, "TEMPERATURE");
        public final static Property TemperatureDate = new Property(16, String.class, "temperatureDate", false, "TEMPERATURE_DATE");
        public final static Property Day = new Property(17, int.class, "day", false, "DAY");
        public final static Property TemperatureThreshold = new Property(18, String.class, "temperatureThreshold", false, "TEMPERATURE_THRESHOLD");
        public final static Property RoomId = new Property(19, int.class, "roomId", false, "ROOM_ID");
    }

    private final StringConverter placesConverter = new StringConverter();
    private final StringConverter peopleConverter = new StringConverter();
    private final StringConverter temperatureConverter = new StringConverter();
    private final StringConverter temperatureDateConverter = new StringConverter();

    public UserBeanDao(DaoConfig config) {
        super(config);
    }
    
    public UserBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"USER_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"IS_ADMIN\" INTEGER NOT NULL ," + // 1: isAdmin
                "\"USER_NAME\" TEXT," + // 2: userName
                "\"USER_PASS\" TEXT," + // 3: userPass
                "\"NAME\" TEXT," + // 4: name
                "\"USER_PHOTO\" TEXT," + // 5: userPhoto
                "\"AGE\" TEXT," + // 6: age
                "\"SEX\" TEXT," + // 7: sex
                "\"ID_CARD\" TEXT," + // 8: idCard
                "\"FAMILY_ADDRESS\" TEXT," + // 9: familyAddress
                "\"HEALTH_IMG_PATH\" TEXT," + // 10: healthImgPath
                "\"HEALTH_MA_IMG_PATH\" TEXT," + // 11: healthMaImgPath
                "\"IS_MAINTAIN\" INTEGER NOT NULL ," + // 12: isMaintain
                "\"PLACES\" TEXT," + // 13: places
                "\"PEOPLE\" TEXT," + // 14: people
                "\"TEMPERATURE\" TEXT," + // 15: temperature
                "\"TEMPERATURE_DATE\" TEXT," + // 16: temperatureDate
                "\"DAY\" INTEGER NOT NULL ," + // 17: day
                "\"TEMPERATURE_THRESHOLD\" TEXT," + // 18: temperatureThreshold
                "\"ROOM_ID\" INTEGER NOT NULL );"); // 19: roomId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"USER_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, UserBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getIsAdmin() ? 1L: 0L);
 
        String userName = entity.getUserName();
        if (userName != null) {
            stmt.bindString(3, userName);
        }
 
        String userPass = entity.getUserPass();
        if (userPass != null) {
            stmt.bindString(4, userPass);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(5, name);
        }
 
        String userPhoto = entity.getUserPhoto();
        if (userPhoto != null) {
            stmt.bindString(6, userPhoto);
        }
 
        String age = entity.getAge();
        if (age != null) {
            stmt.bindString(7, age);
        }
 
        String sex = entity.getSex();
        if (sex != null) {
            stmt.bindString(8, sex);
        }
 
        String idCard = entity.getIdCard();
        if (idCard != null) {
            stmt.bindString(9, idCard);
        }
 
        String familyAddress = entity.getFamilyAddress();
        if (familyAddress != null) {
            stmt.bindString(10, familyAddress);
        }
 
        String healthImgPath = entity.getHealthImgPath();
        if (healthImgPath != null) {
            stmt.bindString(11, healthImgPath);
        }
 
        String healthMaImgPath = entity.getHealthMaImgPath();
        if (healthMaImgPath != null) {
            stmt.bindString(12, healthMaImgPath);
        }
        stmt.bindLong(13, entity.getIsMaintain() ? 1L: 0L);
 
        List places = entity.getPlaces();
        if (places != null) {
            stmt.bindString(14, placesConverter.convertToDatabaseValue(places));
        }
 
        List people = entity.getPeople();
        if (people != null) {
            stmt.bindString(15, peopleConverter.convertToDatabaseValue(people));
        }
 
        List temperature = entity.getTemperature();
        if (temperature != null) {
            stmt.bindString(16, temperatureConverter.convertToDatabaseValue(temperature));
        }
 
        List temperatureDate = entity.getTemperatureDate();
        if (temperatureDate != null) {
            stmt.bindString(17, temperatureDateConverter.convertToDatabaseValue(temperatureDate));
        }
        stmt.bindLong(18, entity.getDay());
 
        String temperatureThreshold = entity.getTemperatureThreshold();
        if (temperatureThreshold != null) {
            stmt.bindString(19, temperatureThreshold);
        }
        stmt.bindLong(20, entity.getRoomId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, UserBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getIsAdmin() ? 1L: 0L);
 
        String userName = entity.getUserName();
        if (userName != null) {
            stmt.bindString(3, userName);
        }
 
        String userPass = entity.getUserPass();
        if (userPass != null) {
            stmt.bindString(4, userPass);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(5, name);
        }
 
        String userPhoto = entity.getUserPhoto();
        if (userPhoto != null) {
            stmt.bindString(6, userPhoto);
        }
 
        String age = entity.getAge();
        if (age != null) {
            stmt.bindString(7, age);
        }
 
        String sex = entity.getSex();
        if (sex != null) {
            stmt.bindString(8, sex);
        }
 
        String idCard = entity.getIdCard();
        if (idCard != null) {
            stmt.bindString(9, idCard);
        }
 
        String familyAddress = entity.getFamilyAddress();
        if (familyAddress != null) {
            stmt.bindString(10, familyAddress);
        }
 
        String healthImgPath = entity.getHealthImgPath();
        if (healthImgPath != null) {
            stmt.bindString(11, healthImgPath);
        }
 
        String healthMaImgPath = entity.getHealthMaImgPath();
        if (healthMaImgPath != null) {
            stmt.bindString(12, healthMaImgPath);
        }
        stmt.bindLong(13, entity.getIsMaintain() ? 1L: 0L);
 
        List places = entity.getPlaces();
        if (places != null) {
            stmt.bindString(14, placesConverter.convertToDatabaseValue(places));
        }
 
        List people = entity.getPeople();
        if (people != null) {
            stmt.bindString(15, peopleConverter.convertToDatabaseValue(people));
        }
 
        List temperature = entity.getTemperature();
        if (temperature != null) {
            stmt.bindString(16, temperatureConverter.convertToDatabaseValue(temperature));
        }
 
        List temperatureDate = entity.getTemperatureDate();
        if (temperatureDate != null) {
            stmt.bindString(17, temperatureDateConverter.convertToDatabaseValue(temperatureDate));
        }
        stmt.bindLong(18, entity.getDay());
 
        String temperatureThreshold = entity.getTemperatureThreshold();
        if (temperatureThreshold != null) {
            stmt.bindString(19, temperatureThreshold);
        }
        stmt.bindLong(20, entity.getRoomId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public UserBean readEntity(Cursor cursor, int offset) {
        UserBean entity = new UserBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getShort(offset + 1) != 0, // isAdmin
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userName
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userPass
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // name
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userPhoto
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // age
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // sex
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // idCard
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // familyAddress
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // healthImgPath
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // healthMaImgPath
            cursor.getShort(offset + 12) != 0, // isMaintain
            cursor.isNull(offset + 13) ? null : placesConverter.convertToEntityProperty(cursor.getString(offset + 13)), // places
            cursor.isNull(offset + 14) ? null : peopleConverter.convertToEntityProperty(cursor.getString(offset + 14)), // people
            cursor.isNull(offset + 15) ? null : temperatureConverter.convertToEntityProperty(cursor.getString(offset + 15)), // temperature
            cursor.isNull(offset + 16) ? null : temperatureDateConverter.convertToEntityProperty(cursor.getString(offset + 16)), // temperatureDate
            cursor.getInt(offset + 17), // day
            cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // temperatureThreshold
            cursor.getInt(offset + 19) // roomId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, UserBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setIsAdmin(cursor.getShort(offset + 1) != 0);
        entity.setUserName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setUserPass(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setUserPhoto(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setAge(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setSex(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setIdCard(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setFamilyAddress(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setHealthImgPath(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setHealthMaImgPath(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setIsMaintain(cursor.getShort(offset + 12) != 0);
        entity.setPlaces(cursor.isNull(offset + 13) ? null : placesConverter.convertToEntityProperty(cursor.getString(offset + 13)));
        entity.setPeople(cursor.isNull(offset + 14) ? null : peopleConverter.convertToEntityProperty(cursor.getString(offset + 14)));
        entity.setTemperature(cursor.isNull(offset + 15) ? null : temperatureConverter.convertToEntityProperty(cursor.getString(offset + 15)));
        entity.setTemperatureDate(cursor.isNull(offset + 16) ? null : temperatureDateConverter.convertToEntityProperty(cursor.getString(offset + 16)));
        entity.setDay(cursor.getInt(offset + 17));
        entity.setTemperatureThreshold(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setRoomId(cursor.getInt(offset + 19));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(UserBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(UserBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(UserBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
